<?php
class Contact extends CI_Controller {
	
	public function __construct()
	{
		parent::__construct();
		$this->load->helper('url');
		$this->load->library('user_agent');
		$this->load->library('email');
	}

	public function index()
	{
		$data['page_title'] = ucfirst('Contact Us'); // Capitalize the first letter
		
		$is_mobile = $this->agent->is_mobile();
		//$is_mobile = true; //uncomment for mobile version
	
		if ($is_mobile) {
			$this->load->view('mobile/templates/header', $data);
			$this->load->view('mobile/contact', $data);
			$this->load->view('mobile/templates/footer', $data);
		} else {
			$this->load->view('web/templates/header', $data);
			$this->load->view('web/contact', $data);
			$this->load->view('web/templates/footer', $data);
		}
	}
	
	public function sendEmail()
	{
		$name = $this->input->post("username"); 
		$email = $this->input->post("email"); 
		$subject = $this->input->post("subject"); 
		$message = $this->input->post("message"); 
		
		$data['page_title'] = ucfirst('Contact Us'); // Capitalize the first letter
		$this->email->from($email, $name);
		$this->email->to('michaelsandic@hotmail.com');
		
		$this->email->subject($subject);
		$this->email->message($message);
		
		$this->email->send();
		echo json_encode(array('result'=>$this->email->send()));
	}
	
	public function emailSucess()
	{
		$data['page_title'] = 'Redirecting ...'; // Capitalize the first letter
		$this->load->view('web/email_sucess');
	}
}
